/*
 * Copyright (C) 2008-2012  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _esymbol_h
#define _esymbol_h

#include "etypes.h"

#define esymbol_p(object)	(etype(object) == t_symbol)

/*
 * Types
 */
struct esymbol {
    esymbol_t		*next;
    eobject_t		 value;
    evector_t		*name;
    eword_t		 key;

    eword_t		 offset;
    etag_t		*tag;
    enamespace_t	*namespace;
    esymbol_t		*parent;

    euint32_t		 type		: 1;
    euint32_t		 keyword	: 1;
    euint32_t		 bound		: 1;
};

struct ebasic {
    esymbol_t		*name;
    etype_t		 type;
    eword_t		 length;
};

struct erecord {
    esymbol_t		*name;
    etype_t		 type;
    eword_t		 length;

    eword_t		 offset;
    ehash_t		*fields;
    evector_t		*vector;

    evector_t		*gcinfo;
    enamespace_t	*parent;
};

/*
 * Prototypes
 */
extern void
init_symbol(void);

extern void
finish_symbol(void);

extern esymbol_t *
enew_identifier(evector_t *name);

extern esymbol_t *
eget_symbol(enamespace_t *namespace, evector_t *name);

extern esymbol_t *
eget_bound_symbol(evector_t *name);

extern esymbol_t *
enew_symbol(enamespace_t *namespace, evector_t *name, etag_t *tag);

extern ebasic_t *
enew_basic(esymbol_t *name, etype_t type, eint32_t length);

extern erecord_t *
enew_record(esymbol_t *name);

extern void
eend_record(erecord_t *record);

extern enamespace_t *
enew_namespace(esymbol_t *name, enamespace_t *parent);

/*
 * Externs
 */
extern evector_t	*type_vector;
extern enamespace_t	*current_namespace;

#endif /* _esymbol_h */
